var initLoadFlag = false;
function loadPanelData(){
	//alert("3");
	loadSpendSummary();
	loadAirSpend();
	loadCarSpend();
	loadHotelSpend();
	loadActiveNewsAlerts();
	loadPolicyStatus();
	loadRailSpend();
	$("#pnlrail_table").datagrid({
		url:'json/aaa.json'
	});
	$("#pnlPlySts_table").datagrid({
		url:'datagrid_data1.json'
	});
	//alert(initLoadFlag);
	if(initLoadFlag==false){
		//alert("testing11");
		initLoadFlag = true;
		//after all data loaded, then timing
		var SysSecond;
	    var InterValObj;
		timer();
		
		//checkbox control 18 panels
		$(":checkbox").click(function(){
	        var panelId = $(this).attr("cor");
	        if(this.checked){
	            $("#" + panelId).panel('open');
	        }else{
	            $("#" + panelId).panel('close');
	        }
		});
		//var leftNavFlag = 0;
		$("#rptsubn").click(function(){
			//if(leftNavFlag==0){
				$("#xportal").load("availableReports.html #greenBackground");
				//leftNavFlag = 1;
			//}else{
				//$("#contentHeader").text("AVAILABLE REPORTS");
				//$(".searchbar div:eq(1)").show();
				//$("#All_Rpt").show();
			//}
			//loadAvailabeReports();
		});
		$("#hmsubn").click(function(){
			$("#xportal").load("portal_o.jsp");//loading portal_o.jsp
		});
		$("#ucsubn").click(function(){
			//if(leftNavFlag==0){
				$("#xportal").load("availableReports.html #greenBackground", function(){
					$("#contentHeader").text("UPCOMING");
					$(".searchbar div:eq(1)").hide();
					$("#All_Rpt").hide();
				});
				//leftNavFlag = 1;
			//}else{
				/*$("#contentHeader").text("UPCOMING");
				$(".searchbar div:eq(1)").hide();
				$("#All_Rpt").hide();*/
			//}
		});
		$("#mpsubn").click(function(){
			//if(leftNavFlag==0){
				$("#xportal").load("availableReports.html #greenBackground", function(){
					$("#contentHeader").text("MOST POPULAR");
					$(".searchbar div:eq(1)").hide();
					$("#All_Rpt").hide();
				});
				//leftNavFlag = 1;
			//}else{
			/*	$("#contentHeader").text("MOST POPULAR");
				$(".searchbar div:eq(1)").hide();
				$("#All_Rpt").hide();*/
			//}
		});
	}
//	loadDoubleClkSpendSummary();//now not using this one, use it later
}

function loadSpendSummary(){
	$('#pnlsmy_data').highcharts({
	    chart: {spacing: [1, 0, 0, 0],marginLeft: 20,marginRight: 5,marginBottom: 50},
	    title: {text: 'Spend Panels (Summary)',style:{fontSize: '13px'}},
	    xAxis: {categories: ['Air', 'Hotel', 'Car', 'Rail']},
	    labels: {
	        items: [{
	            html: 'Year over Year spend (in million)',
	            style: {left: '40px',top: '0px',color: 'black'}
	        }]
	    },
	    legend:{align: 'center'},
	    series: [{type: 'column',name: 'Current YTD',data: [2, 1, 3, 5.5]
	    }, {
	        type: 'column',name: 'Compare YTD',data: [3, 5, 7, 2]
	    }, {
	        type: 'spline',name: 'Average',data: [2.5, 3, 5, 3.75],
	        marker: {
	        	lineWidth: 2,lineColor: Highcharts.getOptions().colors[3],fillColor: 'white'}
	    }, ]
	});
}

function loadAirSpend(){
	   $('#pnlair_data').highcharts({
	    chart: {type: 'bar',spacing: [1, 0, 0, 0],marginLeft: 70,marginRight: 0,marginBottom: 50},
	    title: {text: 'Spend Panels(Air)',style:{fontSize: '13px',top: 25}},
	    xAxis: {
	        categories: ['DOMESTIC', 'EUROPEAN', 'Intl' ],title: {text: null}
	    },
	    tooltip: {valueSuffix: ' millions'},
	    plotOptions: {
	        bar: {dataLabels: {enabled: true}}
	    },
	    legend: {align:'center' },
	    credits: {enabled: false},
	    series: [{
	        name: 'Current YTD',
	        data: [107, 61, 135, ]
	    },  {
	        name: 'Comparison YTD',
	        data: [73, 114, 94, ]
	    }]
	});
}

function loadCarSpend(){
	$('#pnlcar_data').highcharts({
        chart: {zoomType: 'x',spacing: [1, 0, 0, 0],marginLeft: 40,marginRight: 0,marginBottom:25},
        title: {text: 'Spend Panels(Car)',top: 20,
            style:{fontSize: 14,}
        },
        subtitle: {
            text: document.ontouchstart === undefined ?
                'Click and drag in the plot area to zoom in' :
                'Pinch the chart to zoom in'
        },
        xAxis: {
            type: 'datetime',maxZoom: 14 * 24 * 3600000, // fourteen days
            title: {text: null}
        },
        yAxis: {title: {text: null}},
        tooltip: {shared: true},
        legend: {enabled: false},
        plotOptions: {
            area: {
                fillColor: {
                    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
                    stops: [
                        [0, Highcharts.getOptions().colors[0]],
                        [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
                    ]
                },
                lineWidth: 1,marker: {enabled: false},shadow: false,states: {hover: {lineWidth: 1}},threshold: null
            }
        },
        series: [{
            type: 'area',
            name: 'SALES',
            pointInterval: 24 * 3600 * 1000,
            pointStart: Date.UTC(2006, 0, 01),
            data: [
                0.8446, 0.8445, 0.8444, 0.8451,    0.8418, 0.8264,    0.8258, 0.8232,    0.8233, 0.8258,
                0.8283, 0.8278, 0.8256, 0.8292,    0.8239, 0.8239,    0.8245, 0.8265,    0.8261, 0.8269,
                0.8273, 0.8244, 0.8244, 0.8172,    0.8139, 0.8146,    0.8164, 0.82,    0.8269, 0.8269,
                0.8269, 0.8258, 0.8247, 0.8286,    0.8289, 0.8316,    0.832, 0.8333,    0.8352, 0.8357,
                0.8355, 0.8354, 0.8403, 0.8403,    0.8406, 0.8403,    0.8396, 0.8418,    0.8409, 0.8384,
                0.8386, 0.8372, 0.839, 0.84, 0.8389, 0.84, 0.8423, 0.8423, 0.8435, 0.8422,
            ]
        }]
    });
}
function loadHotelSpend(){
	 $('#pnlhotel_data').highcharts({
	    chart: {type: 'bubble',plotBorderWidth: 1,zoomType: 'xy',spacing: [1, 1, 0, 0],
	        marginLeft: 28,marginRight: 5,marginBottom: 52
	    },
	    title: {text: /*null*/ 'Spend Panels(Hotel)',
	        sytle:{fontSize: 11}
	    },
	    xAxis: {gridLineWidth: 1},
	    yAxis: {startOnTick: false,endOnTick: false},
	    series: [{
	    	name:'Current YTD',
	        data: [
	            [9, 81, 63],[98, 5, 89],[51, 50, 73],[41, 22, 14],[58, 24, 20],[78, 37, 34],
	            [55, 56, 53],[18, 45, 70],[42, 44, 28],[3, 52, 59],[31, 18, 97],[79, 91, 63],
	            [93, 23, 23],[44, 83, 22]
	        ],
	        marker: {
	             fillColor: {
	                 radialGradient: { cx: 0.4, cy: 0.3, r: 0.7 },
	                 stops: [[0, 'rgba(255,255,255,0.5)'],[1, 'rgba(69,114,167,0.5)']
	                 ]
	             }
	        }
	    }, {
	    	name:'Comparison YTD',
	        data: [
	            [42, 38, 20],[6, 18, 1],[1, 93, 55],[57, 2, 90],[80, 76, 22],[11, 74, 96],
	            [88, 56, 10],[30, 47, 49],[57, 62, 98],[4, 16, 16],[46, 10, 11],[22, 87, 89],
	            [57, 91, 82],[45, 15, 98]
	        ],
	        marker: {
	             fillColor: {
	                 radialGradient: { cx: 0.4, cy: 0.3, r: 0.7 },
	                 stops: [
	                     [0, 'rgba(255,255,255,0.5)'],
	                     [1, 'rgba(170,70,67,0.5)']
	                 ]
	             }
	        }
	    }]
	
	});	
}

function loadActiveNewsAlerts(){
	/*$("#pnlana_data").load("js/data/ActiveNewsAlerts.data");*/	
}

function loadPolicyStatus(){
	/*$("#pnlplysts_data").load("js/data/PolicyStatus.data");*/
}
function loadRailSpend(){
	/*$("#pnlrail_data").load("js/data/RailSpend.data");*/
}
function loadDoubleClkSpendSummary(){
	$('.barChart2').highcharts({
        title: {text: 'Spend Panels (Summary)'},
        xAxis: {categories: ['Air', 'Hotel', 'Car', 'Rail']},
        labels: {
            items: [{
                html: 'Year over Year spend (in million)',
                style: {left: '40px',top: '8px',color: 'black'}
            }]
        },
        series: [{type: 'column',name: 'Current YTD',
            data: [2, 1, 3, 5.5]
        }, {
            type: 'column',name: 'Comparison YTD',
            data: [3, 5, 7, 2]
        }, {
            type: 'spline',name: 'Average',data: [2.5, 3, 5, 3.75],
            marker: {lineWidth: 2,lineColor: Highcharts.getOptions().colors[3],fillColor: 'white'}
        }, ]
    });
}
//prive formatting for Policy Status
function formatPrice(val,row){
    if (val < 30){
        return '<div style="margin-left:18px;margin-top:2px; float:left;color:red;">'+val+'%</div><div style="margin-left: 6px;margin-top:6px; border:#f15b6c solid 1px; width:6px;height:6px; float:left;border-radius:3px; background-color:red;" class="easyui-tooltip" title="value<30%"></div>';
    } 
    else if(val>30 && val<70){
        return '<div style="margin-left:18px;margin-top:2px; float:left;color:#f15b6c;">'+val+'%</div><div style="margin-left: 6px;margin-top:6px; border:#f15b6c solid 1px; width:6px;height:6px; float:left;border-radius:3px; background-color:#f15b6c;" class="easyui-tooltip" title="30%<=value<70%" ></div>';
    }else if(val>=70 && val<=100){
        return '<div style="margin-left:18px;margin-top:2px; float:left;color:#7fb80e;">'+val+'%</div><div style="margin-left: 6px;margin-top:6px; border:#7fb80e solid 1px; width:6px;height:6px; float:left;border-radius:3px; background-color:#7fb80e;" class="easyui-tooltip" title="value>=70%"></div>';
    }
}

//timer
function timer(){
    SysSecond = parseInt($("#remainSeconds").html());
    InterValObj = window.setInterval(SetRemainTime, 1000);
}
function SetRemainTime(){
	if (SysSecond > 0) {
        SysSecond = SysSecond - 1;
        var second = Math.floor(SysSecond % 60);
        var minite = Math.floor((SysSecond / 60) % 60);
        $("#remainTime").html(minite + ":" + second);
    } else {
        alert("time out");
        window.clearInterval(InterValObj);
    }
}

//load availabe reports
/*function loadAvailabeReports(){
	//$("#pp").load("availableReports.html");
	
}*/

function doubleClick(){
	$('#wSpendPanel').html("");
	$('#wSpendPanel').window('open');
	$("#wSpendPanel").load("18panelsdbclick.html");
}